home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / RAND / UNSPLIT / BM214SRC.ZIP / 68030 / BSPD.S next >
Encoding:
Text File  |  1996-06-29  |  9.6 KB  |  281 lines

  1. *=======================================================*
  2. *    BSP-Descent: latest update 25/03/96        *
  3. *=======================================================*
  4. *    Descend BSP tree, generating sectors & walls.    *
  5. *=======================================================*
  6.  
  7. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  8. *    Descend Binary Space Partitioning Tree        *
  9. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  10.     txtlong
  11. *-------------------------------------------------------*
  12. descend_bsp:
  13. *-------------------------------------------------------*
  14. *    Place start & terminator on heap and descend    *
  15. *-------------------------------------------------------*
  16.     move.l        sp,bsp_return
  17.     lea        display_struct,a6
  18.     move.w        NumNodes,d0
  19.     push.w        #terminator
  20.     subq.w        #1,d0
  21.     push.w        d0
  22.     bra        next_node
  23. *-------------------------------------------------------*
  24. *    Thread returns here when tree is exhausted    *
  25. *-------------------------------------------------------*
  26. finish_tree:
  27. *-------------------------------------------------------*
  28.     move.l        bsp_return,sp
  29.     rts
  30.  
  31. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  32. *    [node] = [sector] -> draw this node        *
  33. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  34.     txtlong
  35. *-------------------------------------------------------*
  36. ssector_node:
  37. *-------------------------------------------------------*
  38. *    Stop drawing when [width] columns are filled    *
  39. *-------------------------------------------------------*
  40.     tst.w        display_columns(a6)
  41.     beq.s        finish_tree
  42. *-------------------------------------------------------*
  43. *    Stop drawing when last node has been popped    *
  44. *-------------------------------------------------------*
  45.     not.w        d0
  46.     beq.s        finish_tree
  47.     eor.w        #$7FFF,d0
  48.  
  49. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  50. *    Render ssector into run-buffer            *
  51. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  52. build_ssector:
  53. *-------------------------------------------------------*
  54. *    Locate [segs] for this [ssector]        *
  55. *-------------------------------------------------------*
  56.     move.l        display_ssectors(a6),a0
  57.     move.w        ssec_first(a0,d0.w*4),d4
  58.     move.w        ssec_segments(a0,d0.w*4),d3
  59. *-------------------------------------------------------*
  60. *    Locate [linedef] & [sidedef] for first [seg]    *
  61. *-------------------------------------------------------*
  62.     move.l        display_segs(a6),a2
  63.     move.w        d4,d2
  64.     mulu.w        #seg_len,d2
  65.     add.l        d2,a2
  66.     move.w        seg_linedef(a2),d0
  67.     move.w        seg_sidedef(a2),d2
  68. *-------------------------------------------------------*
  69. *    Locate right [sidedef] for this [linedef]    *
  70. *-------------------------------------------------------*
  71.     move.l        display_linedefs(a6),a0
  72.     mulu.w        #linedef_len,d0
  73.     add.l        d0,a0
  74.     move.w        linedef_right(a0,d2.w*2),d1 
  75. *-------------------------------------------------------*
  76. *    Locate [sector] for this [sidedef]        *
  77. *-------------------------------------------------------*
  78.     move.l        display_sidedefs(a6),a0
  79.     mulu.w        #sidedef_len,d1
  80.     add.l        d1,a0
  81.     move.w        sidedef_sector(a0),d1    
  82. *-------------------------------------------------------*
  83. *    Set up floor & ceiling heights for this sector    *
  84. *-------------------------------------------------------*
  85.     move.l        display_sectors(a6),a0
  86.     mulu.w        #sector_len,d1
  87.     add.l        d1,a0
  88.     move.l        a0,display_sectorptr(a6)
  89. *-------------------------------------------------------*
  90.     move.w        sector_floorht(a0),display_fh(a6)
  91.     move.w        sector_ceilht(a0),display_ch(a6)
  92.     move.w        sector_ftns(a0),display_ft(a6)
  93.     move.w        sector_ctns(a0),display_ct(a6)
  94. *-------------------------------------------------------*
  95. *    Are we in this sector?                *
  96. *-------------------------------------------------------*
  97.     tst.b        display_firstssec(a6)
  98.     beq.s        .skip
  99.     clr.b        display_firstssec(a6)
  100. *-------------------------------------------------------*
  101. *    Set viewcone to (sector_height+player_height)    *
  102. *-------------------------------------------------------*
  103.     move.w        display_fh(a6),d0
  104.     add.w        #player_height,d0
  105.     add.w        pho,d0
  106.     move.w        d0,display_ph(a6)
  107. *-------------------------------------------------------*
  108. *    Set up segment-heap for loop            *
  109. *-------------------------------------------------------*
  110. .skip:    move.l        d4,d2
  111.     move.w        d2,display_segbase(a6)
  112.     move.w        d3,display_segnum(a6)
  113.     ble        next_node
  114. *-------------------------------------------------------*
  115. *    Process simple lighting effects (temporary!)    *
  116. *-------------------------------------------------------*
  117.     bsr        process_lighting
  118. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  119. *    Render segments surrounding this ssector    *
  120. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  121. segment_loop:
  122. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  123. *    Hidden surface removal stage #1            *
  124. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  125. *    Is viewer on left or right side of this line?    *
  126. *-------------------------------------------------------*
  127. *    ((y2-y1)*(x1-Px))) => (((x2-x1)*(y1-Py)) ?    *
  128. *-------------------------------------------------------*
  129.     move.l        display_vertices(a6),a0
  130.     moveq        #0,d0
  131.     moveq        #0,d1
  132.     move.w        linedef_from(a2),d0
  133.     move.w        linedef_to(a2),d1
  134.     move.w        vtx_x(a0,d0.l*4),d5
  135.     move.w        vtx_x(a0,d1.l*4),d6
  136.     move.w        vtx_y(a0,d0.l*4),d0
  137.     move.w        vtx_y(a0,d1.l*4),d1
  138.     sub.w        d5,d6            ; x2-x1
  139.     sub.w        d0,d1            ; y2-y1
  140.     sub.w        display_px(a6),d5    ; x1-px
  141.     sub.w        display_py(a6),d0    ; y1-py
  142.     muls.w        d6,d0            ; (x2-x1)*(y1-Py)
  143.     muls.w        d5,d1            ; (x1-px)*(y2-y1)
  144.     cmp.l        d0,d1
  145.     bpl        invisible
  146. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  147. *    Segment is visible                *
  148. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
  149.     pea        (a2)
  150. *-------------------------------------------------------*
  151.     move.w        display_segbase(a6),d0
  152.     move.l        display_segs(a6),a5
  153.     mulu.w        #seg_len,d0
  154.     add.l        d0,a5
  155. *-------------------------------------------------------*
  156. *    Locate segment vertices                *
  157. *-------------------------------------------------------*
  158.     move.l        seg_length(a5),umag
  159.     move.w        seg_distance(a5),x_offset
  160.     move.l        display_vertices(a6),a0
  161.     moveq        #0,d0
  162.     move.w        seg_from(a5),d0
  163.     move.l        a0,a1
  164.     moveq        #0,d1
  165.     move.w        seg_to(a5),d1 
  166.     lsl.l        #2,d0
  167.     lsl.l        #2,d1
  168.     add.l        d0,a0            ; a+(d*4)
  169.     add.l        d1,a1            ; a+(d*4)
  170. *-------------------------------------------------------*
  171. *    Fetch X1,Y1 / X2,Y2 & centre around viewpoint    *
  172. *-------------------------------------------------------*
  173.     lea        DSPHostStat.w,a2
  174.     lea        DSPHost16.w,a3
  175.     dspwaitwrite.0    (a2)
  176.     move.w        #projectwall_command,(a3)
  177.     dspwaitwrite.0    (a2)
  178.     move.w        (a0)+,(a3)
  179.     dspwaitwrite.0    (a2)
  180.     move.w        (a0)+,(a3)
  181.     dspwaitwrite.0    (a2)
  182.     move.w        (a1)+,(a3)
  183.     dspwaitwrite.0    (a2)
  184.     move.w        (a1)+,(a3)
  185.     lea        DSPHost32.w,a4
  186.     dspwaitread.0    (a2)
  187.     tst.w        (a3)
  188.     beq        end_segment
  189.     dspwaitread.0    (a2)
  190.     move.l        (a4),d3
  191.     lsl.l        #8,d3
  192.     dspwaitread.0    (a2)
  193.     move.l        (a4),d4
  194.     lsl.l        #8,d4
  195.     dspwaitread.0    (a2)
  196.     move.l        (a4),d5
  197.     lsl.l        #8,d5
  198.     dspwaitread.0    (a2)
  199.     move.l        (a4),d6
  200.     lsl.l        #8,d6
  201.     dspwaitread.0    (a2)
  202.     move.l        (a4),d1
  203.     lsl.l        #8,d1
  204.     dspwaitread.0    (a2)
  205.     move.l        (a4),d2
  206.     lsl.l        #8,d2
  207. *-------------------------------------------------------*
  208. *    Write coordinates into addwall struct        *
  209. *-------------------------------------------------------*
  210. .draw:    move.l        d1,addwall_rz2(a6)
  211.     move.l        d2,addwall_rz1(a6)
  212.     move.l        d3,addwall_i1(a6)
  213.     move.l        d4,addwall_z1(a6)
  214.     move.l        d5,addwall_i2(a6)
  215.     move.l        d6,addwall_z2(a6)
  216. *-------------------------------------------------------*
  217. *    Look up linedef for this seg            *
  218. *-------------------------------------------------------*
  219.     move.w        seg_linedef(a5),d1
  220.     move.l        display_linedefs(a6),a0
  221.     mulu.w        #linedef_len,d1
  222.     add.l        d1,a0
  223. *-------------------------------------------------------*
  224. *    Determine one or two-sided linedef        *
  225. *-------------------------------------------------------*
  226.     move.w        linedef_attrib(a0),d0
  227.     or.w        #$100,linedef_attrib(a0)
  228.     move.b        d0,linedef_flags
  229.     and.b        #attrib_twosided,d0
  230.     move.b        d0,twosided_flag
  231. *-------------------------------------------------------*
  232. *    Determine which sidedef is facing us        *
  233. *-------------------------------------------------------*
  234.     move.w        seg_sidedef(a5),d0
  235.     move.w        linedef_right(a0,d0.w*2),d5    ; visible sidedef
  236.     bchg        #0,d0
  237.     move.w        linedef_right(a0,d0.w*2),d6    ; invisible sidedef
  238. *-------------------------------------------------------*
  239. *    Look up sidedef for visible side of linedef    *
  240. *-------------------------------------------------------*
  241.     move.l        display_sidedefs(a6),a3
  242.     mulu.w        #sidedef_len,d5
  243.     move.l        a3,a4
  244.     add.l        d5,a3
  245. *-------------------------------------------------------*
  246. *    Locate [sector] on opposite side of [linedef]    *
  247. *-------------------------------------------------------*
  248.     tst.b        twosided_flag
  249.     beq.s        .nts
  250.     mulu.w        #sidedef_len,d6
  251.     add.l        d6,a4
  252.     move.w        sidedef_sector(a4),d6        ; a+(d*30)
  253.     move.l        display_sectors(a6),a4
  254.     mulu.w        #sector_len,d6
  255.     add.l        d6,a4
  256. .nts:    move.b        #0,addwall_opaque(a6)
  257.     tst.b        twosided_flag
  258.     beq        sector_wall
  259.  
  260. *-------------------------------------------------------*
  261. *    Check for lower wall texture            *
  262. *-------------------------------------------------------*
  263. lower_texture:
  264. *-------------------------------------------------------*
  265.     move.l        display_sectorptr(a6),a5
  266.     move.w        sidedef_ltns(a3),d0
  267. *-------------------------------------------------------*
  268. *    Determine wall height                *
  269. *-------------------------------------------------------*
  270.     move.w        sector_floorht(a4),d1
  271.     cmp.w        sector_ceilht(a5),d1
  272.     bmi.s        .clip
  273.     move.w        sector_ceilht(a5),d1
  274. .clip:    move.w        sector_floorht(a5),d2 
  275.     neg.w        d1
  276.     add.w        display_ph(a6),d1
  277.     neg.w        d2
  278.     add.w        display_ph(a6),d2
  279. *-------------------------------------------------------*
  280. *    Render     
  281. *-------------------------------------------!!